import { connect } from 'dva-no-router'
import React, { Component } from 'react'
import { back } from '../utils/navigation'
import { Container, Header, Title, Button, Left, Right, Body, Icon, Text, Grid, Col } from 'native-base'
import Content from '../components/MyContent'

class Login extends Component {

    componentDidMount() {
        const {
            account, name, token
        } = this.props.user
        if (account == null && name == null && token == null) {
            this.props.dispatch({ type: 'user/POST_login' })
        }
    }

    handlePressLogin = () => {
        this.props.dispatch({ type: 'user/POST_logout' })
        back(null)
    }

    render() {
        const {
            account, name, token
        } = this.props.user
        return (
            <Container>
                <Header style={{ backgroundColor: '#DC143C' }}>
                    <Left />
                    <Body>
                        <Title>Login</Title>
                    </Body>
                    <Right>
                        <Button transparent onPress={this.handlePressLogin}>
                            <Text>Close</Text>
                        </Button>
                    </Right>
                </Header>
                <Content contentContainerStyle={{ flex: 1 }}>
                    <Grid style={{ alignItems: 'center' }}>
                        <Col style={{ alignItems: 'center' }}>
                            {account ? <Text>account: {account}</Text> : null}
                            {name ? <Text>name: {name}</Text> : null}
                            {token ? <Text>token: {token}</Text> : null}
                        </Col>
                    </Grid>
                </Content>
            </Container>
        )
    }
}


export default connect(state => state)(Login)
